package chances.epg.config;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.PageContext;

import chances.epg.commons.utils.RequestUtils;
import chances.epg.navigator.EpgConstants;
import chances.epg.navigator.context.AccessContext;
import chances.epg.navigator.history.NavigateHistory;
import chances.epg.session.UserSessionHelper;

public class EpgUIResolverImpl implements chances.epg.ui.config.EpgUIResolver {

	@Override
	public Object getUser(PageContext pageContext) {
		return UserSessionHelper.getUserSession((HttpServletRequest) pageContext.getRequest());
	}

	@Override
	public String getBackUrl(PageContext pageContext) {
		return (String) pageContext.findAttribute(EpgConstants.RETURN_URL);
	}

	@Override
	public String getFocusId(PageContext pageContext) {
		return pageContext.getRequest().getParameter(EpgConstants.ENTRY_FOCUS_ID);
	}

	@Override
	public Object getHistory(PageContext pageContext) {
		HttpServletRequest httpRequest = (HttpServletRequest) pageContext.getRequest();
		HttpSession session = httpRequest.getSession();
		String path = RequestUtils.getRequestPath((HttpServletRequest) pageContext.getRequest());
		NavigateHistory history = (NavigateHistory) session.getAttribute(NavigateHistory.ACCESS_HISTORY_NAME);
		return history;
	}

	@Override
	public Object getAccessContext(PageContext pageContext) {
		return pageContext.findAttribute(EpgConstants.EPG_CONTEXT);
	}

	@Override
	public String getResourcePath(PageContext pageContext) {
		return (String) pageContext.findAttribute(EpgConstants.EPG_RESOURCE_PATH);
	}

	@Override
	public String getSiteCode(PageContext pageContext) {
		AccessContext accessContext = (AccessContext)pageContext.findAttribute(EpgConstants.EPG_CONTEXT);
		return accessContext.getSiteCode();
	}
	

}
